/*******************************************************************************
 * @project: Capital-AVIDM4
 * @package: com.acconsys.avidm4.ui
 * @file: DesignListCellRenderer.java
 * @author: Fionn
 * @created: 2013-3-26
 * @purpose:
 * 
 * @version: 1.0
 * 
 * Revision History at the end of file.
 * 
 * Copyright 2013 AcconSys All rights reserved.
 ******************************************************************************/

/**
 * 
 */
package com.esoon.cdms.decoration;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.JOptionPane;

import com.esoon.cdms.model.BuildListListModel;
import com.esoon.cdms.model.BuildListModel;
import com.esoon.cdms.model.DesignModel;
import com.esoon.cdms.model.ProjectModel;
import com.mentor.chs.api.IXBuildList;
import com.mentor.chs.api.IXDesign;
import com.mentor.chs.api.IXDiagram;

/**
 * @author Fionn
 * 
 */
public class DesignListCellRenderer extends DefaultListCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6233166089120504196L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing
	 * .JList, java.lang.Object, int, boolean, boolean)
	 */
	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
//		JOptionPane.showMessageDialog(null, value);
		// TODO Auto-generated method stub
		if (value instanceof IXDesign) {
			IXDesign design = (IXDesign) value;
			setText(design.getAttribute("Name") + " ("
					+ design.getAttribute("Revision") + ") - "
					+ design.getAttribute("Description"));
			setBackground(isSelected ? Color.ORANGE : Color.WHITE);
			setForeground(isSelected ? Color.BLACK : Color.BLACK);
			return this;
		} else if (value instanceof IXBuildList) {
			IXBuildList buildlist = (IXBuildList) value;
			setText(buildlist.getAttribute("Name"));
			setBackground(isSelected ? Color.ORANGE : Color.WHITE);
			setForeground(isSelected ? Color.BLACK : Color.BLACK);
			return this;
		} else if (value instanceof IXDiagram) {
			IXDiagram diagram = (IXDiagram) value;
			setText(diagram.getAttribute("Name"));
			setBackground(isSelected ? Color.ORANGE : Color.WHITE);
			setForeground(isSelected ? Color.BLACK : Color.BLACK);
			return this;
		}else if (value instanceof DesignModel) {
			DesignModel designModel = (DesignModel) value;
			setText(designModel.getName()+"【"+designModel.getRevision()+"】");
			setBackground(isSelected ? Color.ORANGE : Color.WHITE);
			setForeground(isSelected ? Color.BLACK : Color.BLACK);
			return this;
		} else if (value instanceof ProjectModel) {
			ProjectModel projectModel = (ProjectModel) value;
			setText(projectModel.getName());
			setBackground(isSelected ? Color.ORANGE : Color.WHITE);
			setForeground(isSelected ? Color.BLACK : Color.BLACK);
			return this;
		}else if (value instanceof BuildListModel) {
			BuildListModel buildListModel = (BuildListModel) value;
			setText(buildListModel.getName());
			setBackground(isSelected ? Color.ORANGE : Color.WHITE);
			setForeground(isSelected ? Color.BLACK : Color.BLACK);
			return this;
		} else {
			return super.getListCellRendererComponent(list, value, index,
					isSelected, cellHasFocus);
		}
	}

}

/*******************************************************************************
 * <B>Revision History</B><BR>
 * [type 'revision' and press Alt + / to insert revision block]<BR>
 * 
 * 
 * 
 * Copyright 2013 AcconSys All rights reserved.
 ******************************************************************************/
